package com.yanyu.space.common.core.util;

import java.util.Optional;

/**
 * @author yanyu
 */
public class ObjectUtil {

    public static Long objToLong(Object value) {
        return objToLong(value, 0L);
    }

    public static Long objToLong(Object value, Long defaultVal) {
        return Optional.ofNullable(value).map(item -> Long.valueOf(String.valueOf(value))).orElse(defaultVal);
    }

    public static Integer objToInt(Object value) {
        return objToInt(value, 0);
    }

    public static Integer objToInt(Object value, Integer defaultVal) {
        return Optional.ofNullable(value).map(item -> Integer.valueOf(String.valueOf(value))).orElse(defaultVal);
    }
}
